package cn.dzh.controller;

import cn.dzh.facade.CommodityOperation;
import cn.dzh.model.bean.CommodityDraft;
import cn.dzh.model.dto.GoodsOperateDTO;
import cn.dzh.model.dto.HttpResult;
import cn.dzh.model.dto.Result;
import cn.dzh.service.CommodityOperateService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version V1.0
 * @description:
 * @date: 2023/10/24
 */
@RestController
@RequestMapping("/operation")
public class OperationController implements CommodityOperation{
    @Resource
    private CommodityOperateService commodityOperateService;

    @PostMapping("/goodsOffline")

    public HttpResult goodsOffline(@Validated GoodsOperateDTO goodsOperateDTO){
        Result result = commodityOperateService.goodsOffline(goodsOperateDTO);
        boolean o = (boolean) result.getResult();
        if (!o){
            return HttpResult.error(100002,result.getMsg());
        }
        return HttpResult.ok("商品下线成功");
    }
    @PostMapping("/goodsOnline")
    public HttpResult goodsOnline(@Validated GoodsOperateDTO goodsOperateDTO){
        Result result = commodityOperateService.goodsOnline(goodsOperateDTO);
        boolean o = (boolean) result.getResult();
        if (!o){
            return HttpResult.error(100001,result.getMsg());
        }
        return HttpResult.ok("商品上线成功");
    }



    @PostMapping("/pushAudit")
    public HttpResult pushAudit(@Validated GoodsOperateDTO goodsOperateDTO){
        Result result = commodityOperateService.pushAudit(goodsOperateDTO);
        boolean o = (boolean) result.getResult();
        if (!o){
            return HttpResult.error(100003,result.getMsg());
        }
        return HttpResult.ok("商品提交审核成功");
    }

    @PostMapping("/approv")
    public HttpResult approv(@Validated GoodsOperateDTO goodsOperateDTO){
        Result result = commodityOperateService.approv(goodsOperateDTO);
        boolean o = (boolean) result.getResult();
        if (!o){
            return HttpResult.error(100004,result.getMsg());
        }
        return HttpResult.ok("审核成功");
    }

    @PostMapping("/reject")
    public HttpResult reject(@Validated GoodsOperateDTO goodsOperateDTO){
        Result result = commodityOperateService.reject(goodsOperateDTO);
        boolean o = (boolean) result.getResult();
        if (!o){
            return HttpResult.error(100005,result.getMsg());
        }
        return HttpResult.ok("驳回成功");
    }



    @PostMapping("/addToBase")
    public HttpResult addToBase(@RequestBody CommodityDraft commodityDraft){
        System.out.println(commodityDraft.getId());
        Boolean flag = commodityOperateService.addToBase(commodityDraft.getId());
        if (!flag){
            return HttpResult.error(1231,"插入失败");
        }else{
            return HttpResult.ok("插入成功");
        }
    }



}
